﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreUtils.Common
{
    /// <summary>
    /// Control processing
    /// </summary>
    public class Controls
    {
        /// <summary>
        /// Get all children control by type
        /// </summary>
        /// <param name="control"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        /// <remarks>xula@vnext.vn</remarks>
        public static IEnumerable<System.Windows.Forms.Control> GetAll(System.Windows.Forms.Control control,
            Type type)
        {
            var controls = control.Controls.Cast<System.Windows.Forms.Control>();

            return controls.SelectMany(ctrl => GetAll(ctrl, type))
                                      .Concat(controls)
                                      .Where(c => c.GetType() == type);
        }
    }
}
